package com.yyy.controller;

import com.yyy.pojo.tb_door;
import com.yyy.pojo.tb_order;
import com.yyy.service.Tb_DoorService;
import com.yyy.serviceImpl.Tb_OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
public class Tb_OrderController {
    @Autowired
    Tb_OrderServiceImpl tb_orderService;

    @Autowired
    Tb_DoorService tb_doorService;

    @RequestMapping("/orderList")
    public String orderList(Model model){
        //查询所有订单信息
        List<tb_order> all = tb_orderService.findAll();
        for (tb_order item:all
             ) {
            System.out.println(item.toString());
        }
        //查询所有的门店信息
        List<tb_door> all1 = tb_doorService.findAll();
        model.addAttribute("orderList",all);
        model.addAttribute("doorList",all1);
        return "order_list";


    }

    //打开新增订单界面
    @RequestMapping("/toAddOrder")
    public String toAddOrder(Model model){
        //查询门店信息
        List<tb_door> all = tb_doorService.findAll();
        model.addAttribute("list",all);
        return "order_add";
    }
    @RequestMapping("/orderAdd")
    public String orderAdd(tb_order tb_order){
        Date date=new Date();
        tb_order.setOrderTime(date);
        tb_order.setPayTime(date);
        tb_orderService.insertOne(tb_order);
        return "redirect:/orderList";
    }

    //打开订单信息修改界面
    @RequestMapping("orderInfo")
    public String orderInfo(Integer id,Model model){
        tb_order tb_order = tb_orderService.findById(id);
        List<tb_door> all = tb_doorService.findAll();
        model.addAttribute("doorList",all);
        model.addAttribute("order",tb_order);
        return "order_update";


    }
    //根据id修改界面
    @RequestMapping("/orderUpdate")
    public String orderUpdate(tb_order tb_order){
        int i = tb_orderService.updateById(tb_order);
        return "redirect:/orderList";

    }
    //根据id删除订单信息
    @RequestMapping("/orderDelete")
    public String orderDelete(Integer id){
        tb_orderService.deleteById(id);
        return "redirect:/orderList";
    }

}
